<?php 

	define ('DB_HOST','localhost');
	define ('DB_USER','postgres');
	define ('DB_PASS','lalilulelo7');
	define ('DB_NAME','eMarket');
	define ('DB_PORT','5432');
	
	
		function get_active_users()
		{
			$conn = pg_connect("user=".DB_USER." password=".DB_PASS." port=".DB_PORT." dbname=".DB_NAME." host=".DB_HOST);
			$people = null;
			if ($conn) {
			
				$result = pg_query($conn, "SELECT * FROM USUARIOS WHERE REG_ACT = TRUE");
				return $result;
			}
			else
			{
				echo "Wrong connection...";
				exit;
			}
		}
		
		function get_inactive_users()
		{
			$conn = pg_connect("user=".DB_USER." password=".DB_PASS." port=".DB_PORT." dbname=".DB_NAME." host=".DB_HOST);
			$people = null;
			if ($conn) {
			
				$result = pg_query($conn, "SELECT * FROM USUARIOS WHERE REG_ACT = FALSE");
				return $result;
			}
			else
			{
				echo "Wrong connection...";
				exit;
			}
			
		}
		
		function get_single_user($user_id)
		{
			$conn = pg_connect("user=".DB_USER." password=".DB_PASS." port=".DB_PORT." dbname=".DB_NAME." host=".DB_HOST);
			$people = null;
			if ($conn) {
			
				$result = pg_query($conn, "SELECT * FROM USUARIOS WHERE ID_USUARIO = ".$user_id.";");
				return $result;
			}
			else
			{
				echo "Wrong connection...";
				exit;
			}
			
		}
		
		function update_user_state($user_id, $state)
		{
			$conn = pg_connect("user=".DB_USER." password=".DB_PASS." port=".DB_PORT." dbname=".DB_NAME." host=".DB_HOST);
 
			if ($conn) {
				$result = pg_query($conn, "UPDATE USUARIOS SET REG_ACT = ".$state." WHERE ID_USUARIO = ".$user_id.";");
			}
			else
			{
				echo "Wrong connection...";
				exit;
			}
		}
?>